/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfoexam.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfoexam.entity.CampusinfoTrain;
import com.lczyfz.campusinfo.modules.campusinfoexam.service.CampusinfoTrainService;

/**
 * 考证培训管理Controller
 *
 * @author yt
 * @version 2017-10-20
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfoexam/campusinfoTrain")
public class CampusinfoTrainController extends BaseController {

    @Autowired
    private CampusinfoTrainService campusinfoTrainService;

    @ModelAttribute
    public CampusinfoTrain get(@RequestParam(required = false) String id) {
        CampusinfoTrain entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = campusinfoTrainService.get(id);
        }
        if (entity == null) {
            entity = new CampusinfoTrain();
        }
        return entity;
    }

    @RequiresPermissions("campusinfoexam:campusinfoTrain:view")
    @RequestMapping(value = {"list", ""})
    public String list(CampusinfoTrain campusinfoTrain, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<CampusinfoTrain> page = campusinfoTrainService.findPage(new Page<CampusinfoTrain>(request, response), campusinfoTrain);
        model.addAttribute("page", page);
        return "modules/campusinfoexam/campusinfoTrainList";
    }

    @RequiresPermissions("campusinfoexam:campusinfoTrain:view")
    @RequestMapping(value = "form")
    public String form(CampusinfoTrain campusinfoTrain, Model model) {
        model.addAttribute("campusinfoTrain", campusinfoTrain);
        return "modules/campusinfoexam/campusinfoTrainForm";
    }

    @RequiresPermissions("campusinfoexam:campusinfoTrain:edit")
    @RequestMapping(value = "save")
    public String save(CampusinfoTrain campusinfoTrain, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, campusinfoTrain)) {
            return form(campusinfoTrain, model);
        }
        campusinfoTrainService.save(campusinfoTrain);
        addMessage(redirectAttributes, "保存考证培训信息成功");
        return "redirect:" + Global.getAdminPath() + "/campusinfoexam/campusinfoTrain/?repage";
    }

    @RequiresPermissions("campusinfoexam:campusinfoTrain:edit")
    @RequestMapping(value = "delete")
    public String delete(CampusinfoTrain campusinfoTrain, RedirectAttributes redirectAttributes) {
        campusinfoTrainService.delete(campusinfoTrain);
        addMessage(redirectAttributes, "删除考证培训信息成功");
        return "redirect:" + Global.getAdminPath() + "/campusinfoexam/campusinfoTrain/?repage";
    }

}